budgetThird = 1;
const treeFun = (function () {

  localStorage.removeItem("Clkxs")
  localStorage.removeItem("Cwldw")
  localStorage.removeItem("CnodeDept")
  localStorage.removeItem("Chtbh")
  localStorage.removeItem("Crwh")
  const parlaikuanmingxiTableItemName = localStorage.getItem("laikuanmingxiTableItemName")
  let rootName = localStorage.getItem("rootName");
  let fromGuanxitu = localStorage.getItem("fromGuanxitu");

  console.log(rootName, fromGuanxitu, ' 传值的 该top10中item的rootName')
  //左侧(来款项目预算总额)
  let rateparams = {
    username: getUsername,
    budgetYear: localStorage.getItem("year"),
    budgetMonth: localStorage.getItem("month"),
    projectLb: parlaikuanmingxiTableItemName,
    status: 2,
    chartPage: 70605,
    chartNo: 5
  }
  $.get(
    `${API_URL}getdata`, {
      ...rateparams
    },
    function (res) {
      let re = eval("(" + res + ")");
      let data = re.items[0].charts[0].data;
      if (data.length > 0) {
        document.querySelector('.vessel .aside').innerHTML = `
										<div class="title">
											<span class="third"> 来款情况 /</span>
											<span class="fourth">${parlaikuanmingxiTableItemName}/</span>
											<h4 style="word-wrap: break-word;overflow: auto;">${rootName}</h4>
										</div>
										<div class="budget">
											<h3>来款预算总额</h3>
											<h2>${data[0].key01}<span>万元</span></h2>
										</div>
										<div class="statistics">
											<h4>实际来款总额</h4>
											<h3>${data[0].key02}<span>万元</span></h3>
										</div>
									
										<div class="statistics">
											<h4>完成率</h4>
											<h3>${data[0].key03}%</h3>
											<div class="progress-bar">
												<div style="width: ${data[0].key03}%;" class="progress background-color:${data[0].key03 >= 100 ? "#F53F3F" : "#165DFF"}"></div>
											</div>
										</div>`
      }

      //来款情况 跳转
      document.querySelector('.third').onclick = function () {
        window.location.href = 'Statistics-Incoming.html';
      }

      document.querySelector('.fourth').onclick = function () {
        window.location.href = 'budget-IncomingPayment.html';
      }
    }

  )
  if (fromGuanxitu == 0) {
    laikuanxingshiGuanxitu(rootName)
    localStorage.setItem("Clkxs", rootName)
  }
  if (fromGuanxitu == 1) {
    wanglaidanweiGuanxitu(rootName)
    localStorage.setItem("Cwldw", rootName)
  }
  if (fromGuanxitu == 2) {
    bumenGuanxitu(rootName)
    localStorage.setItem("CnodeDept", rootName)

  }
  if (fromGuanxitu == 3) {
    hetongGuanxitu(rootName)
    localStorage.setItem("Chtbh", rootName)

  }
  if (fromGuanxitu == 4) {
    renwuhaoGuanxitu(rootName)
    localStorage.setItem("Crwh", rootName)
  }

  function laikuanxingshiGuanxitu(rootName) {
    var obj = {
      username: getUsername,
      budgetYear: localStorage.getItem("year"),
      budgetMonth: localStorage.getItem("month"),
      projectLb: parlaikuanmingxiTableItemName,
      status: 2,
      chartPage: 70606,
      chartNo: 6,
      key01: rootName
    }
    ApiGet("getdata", obj, function (e) {
      var json = JSON.parse(e);
      let data = json.items[0].charts[0].data;
      getTree(data)
      console.log(data, '多维度--来款形式维度')
    })
  }

  function wanglaidanweiGuanxitu(rootName) {
    var obj = {
      username: getUsername,
      budgetYear: localStorage.getItem("year"),
      budgetMonth: localStorage.getItem("month"),
      projectLb: parlaikuanmingxiTableItemName,
      status: 2,
      chartPage: 70606,
      chartNo: 1,
      key01: rootName
    }
    ApiGet("getdata", obj, function (e) {
      var json = JSON.parse(e);
      let data = json.items[0].charts[0].data;
      console.log(data, '多维度--往来单位维度')
      getTree(data)
    })
  }

  function bumenGuanxitu(rootName) {
    console.log(rootName, 'lalalal')
    var obj = {
      username: getUsername,
      budgetYear: localStorage.getItem("year"),
      budgetMonth: localStorage.getItem("month"),
      projectLb: parlaikuanmingxiTableItemName,
      status: 2,
      chartPage: 70606,
      chartNo: 2,
      key01: rootName
    }
    ApiGet("getdata", obj, function (e) {
      var json = JSON.parse(e);
      let data = json.items[0].charts[0].data;
      console.log(data, '多维度--部门维度')
      getTree(data)
    })
  }

  function hetongGuanxitu(rootName) {
    var obj = {
      username: getUsername,
      budgetYear: localStorage.getItem("year"),
      budgetMonth: localStorage.getItem("month"),
      projectLb: parlaikuanmingxiTableItemName,
      status: 2,
      chartPage: 70606,
      chartNo: 3,
      key01: rootName
    }
    ApiGet("getdata", obj, function (e) {
      var json = JSON.parse(e);
      let data = json.items[0].charts[0].data;
      console.log(data, '多维度--合同维度')
      getTree(data)

    })
  }

  function renwuhaoGuanxitu(rootName) {
    var obj = {
      username: getUsername,
      budgetYear: localStorage.getItem("year"),
      budgetMonth: localStorage.getItem("month"),
      projectLb: parlaikuanmingxiTableItemName,
      status: 2,
      chartPage: 70606,
      chartNo: 4,
      key01: rootName
    }
    ApiGet("getdata", obj, function (e) {
      var json = JSON.parse(e);
      let data = json.items[0].charts[0].data;
      console.log(data, '多维度--任务号维度')
      getTree(data)
    })
  }

  function getTree(data) {
    console.log(data)
    let allData = data;
    if (rootName) {
      allData = allData
    }
    have("tree-chart") ? dimensionTree("tree-chart", allData) : "";
  }

  document.querySelector('.mask-wrap .mask-title img').onclick = function () {
    document.querySelector('#rateMask').style.display = 'none'
  }
  return {
    getMonPayComplete,
    // getratestate
  }



})()
let lkxsName = ''
let wldwName = ''
let nodeDeptName = ''
let htbhName = ''
let rwhName = ''

function treeNodeclick(param) {
  console.log(param)
  console.log(param.data.pName1)
  if (param.data.pName1) {
    if (param.data.pName1 == '来款方式') {
      wldwName = '';
      nodeDeptName = '';
      htbhName = '';
      rwhName = '';
      lkxsName = param.data.pName2
    }
    if (param.data.pName1 == '往来单位') {
      lkxsName = '';
      nodeDeptName = '';
      htbhName = '';
      rwhName = '';
      wldwName = param.data.pName2
      console.log(wldwName, 'wldwName')
    }
    if (param.data.pName1 == '部门') {
      lkxsName = '';
      wldwName = '';
      htbhName = '';
      rwhName = '';
      nodeDeptName = param.data.pName2
    }
    if (param.data.pName1 == '合同') {
      lkxsName = '';
      wldwName = '';
      nodeDeptName = '';
      rwhName = '';
      htbhName = param.data.pName2
    }
    if (param.data.pName1 == '任务号') {
      lkxsName = '';
      wldwName = '';
      nodeDeptName = '';
      htbhName = '';
      rwhName = param.data.pName2
    }
  }



  if (param.data.num) {
    getMonPayComplete()
    // treeFun.getratestate()
    document.querySelector('#rateMask').style.display = 'block'

  }
}

//月度到款执行
function getMonPayComplete() {
  $.get(
    `${API_URL}getdata`, {
      username: getUsername,
      budgetYear: localStorage.getItem("year"),
      budgetMonth: localStorage.getItem("month"),
      projectLb: localStorage.getItem("laikuanmingxiTableItemName"),
      status: 2,
      chartPage: 70606,
      chartNo: 5,
      wldw: localStorage.getItem("Cwldw") ? localStorage.getItem("Cwldw") : wldwName,
      nodeDept: localStorage.getItem("CnodeDept") ? localStorage.getItem("CnodeDept") : nodeDeptName,
      htbh: localStorage.getItem("Chtbh") ? localStorage.getItem("Chtbh") : htbhName,
      rwh: localStorage.getItem("Crwh") ? localStorage.getItem("Crwh") : rwhName,
      dklx: localStorage.getItem("Clkxs") ? localStorage.getItem("Clkxs") : lkxsName,
    },
    function (res) {
      let re = eval("(" + res + ")");
      console.log(re)
      let data = re.items[0].charts[0].data;
      if (data.length === 0) {
        document.querySelector('#rateMask .mask-scroll .month').style.display = 'none'
        return
      }
      let xData = [];
      let currYearBudget = [];
      let legendData = ["执行金额"];
      for (var i = 0; i < data.length; i++) {
        xData.push(+data[i].key01);
        currYearBudget.push(data[i].key02);
      }
      let Data = [{
        name: "执行金额",
        type: "bar",
        barWidth: '30%',
        barGap: 0,
        itemStyle: {
          color: "#50CD89",
        },
        data: currYearBudget,
      }];
      have("monthlj") ? mulitYBBar("monthlj", xData, legendData, Data, '月', true, false) : "";
    })
}